//
//  WENTabBar.m
//  仿百思不得姐
//
//  Created by wen on 2018/2/7.
//  Copyright © 2018年 wen. All rights reserved.
//

#import "WENTabBar.h"

@interface WENTabBar ()

//发布按钮
@property(nonatomic,weak)UIButton *publishBtn;
@end

@implementation WENTabBar

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        //创建子控件
        UIButton *publish = [[UIButton alloc] init];
        [publish setBackgroundImage:[UIImage imageNamed:@"tabBar_publish_icon"] forState:UIControlStateNormal];
        
        [publish setBackgroundImage:[UIImage imageNamed:@"tabBar_publish_icon_click"] forState:UIControlStateSelected];
        
        [self addSubview:publish];
        self.publishBtn = publish;
    }
    return self;
}

//用来布局子控件
- (void)layoutSubviews {

    [super layoutSubviews];
    
    //布局子控件
    self.publishBtn.bounds = CGRectMake(0, 0, self.publishBtn.currentBackgroundImage.size.width, self.publishBtn.currentBackgroundImage.size.height);
    
    self.publishBtn.center = CGPointMake(self.frame.size.width * 0.5, self.frame.size.height * 0.5);
    
    //拿出子控件布局 UITabBarButton
    //注意点:UITabBarButton 是系统没有提供出来的一个类
    
    int index = 0;
    CGFloat W = self.frame.size.width * 0.2;
    CGFloat H = self.frame.size.height;
    CGFloat Y = 0;
    
    
    for (UIView *view in self.subviews) {
        if ([view isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
//            NSLog(@"%@",view);
            
            CGFloat X = W * ((index == 2)? ++index : index);
            view.frame = CGRectMake(X, Y, W, H);
            index ++;
        }
    }
    
}




@end
